package com.zmn.plat.common.dictionary;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 渠道接入方式枚举
 *
 * @author linfeng
 * @since 2019 /10/31 14:56:30
 */
public enum ChannelAcessModeEnum {

    /**
     * values
     */
    TRAFFICACESS(1, "话务接入"),
    H5(2, "H5"),
    API(3, "API"),
    TEMPORARY(4, "临时接入"),
    ONLINE_CUSTOMER_SERVICE(5, "网络客服接入"),
    CHANNEL_AND_PORTAL_ACCESS(6, "渠道门户接入"),

    ;

    /**
     * 话务接入
     */
    public static final int CONSTS_TRAFFICACESS = 1;
    /**
     * H5
     */
    public static final int CONSTS_H5 = 2;
    /**
     * API
     */
    public static final int CONSTS_API = 3;
    /**
     * 临时接入
     */
    public static final int CONSTS_TEMPORARY = 4;
    /**
     * 网络客服接入
     */
    public static final int ONLINE_CUSTOMER = 5;
    /**
     * 渠道门户接入
     */
    public static final int CHANNEL_ACCESS = 5;

    private Integer code;
    private String name;

    ChannelAcessModeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static ChannelAcessModeEnum of(Integer code) {
        if (code == null) {
            return null;
        }
        switch (code) {
            case 1:
                return TRAFFICACESS;
            case 2:
                return H5;
            case 3:
                return API;
            case 4:
                return TEMPORARY;
            case 5:
                return ONLINE_CUSTOMER_SERVICE;
            case 6:
                return CHANNEL_AND_PORTAL_ACCESS;

            default:
                return null;
        }
    }

    public static String getName(Integer code) {
        ChannelAcessModeEnum of = of(code);
        return of == null ? null : of.getName();
    }

    public static String getIncludeName(String code) {
        String[] codes = code.split(",", -1);
        List<String> list = new ArrayList<>();
        Arrays.stream(codes).forEach(x -> {
            ChannelAcessModeEnum of = of(Integer.parseInt(x));
            if (null != of) {
                list.add(of.getName());
            }
        });
        return String.join(",", list);
    }
}
